package chapter01;

public class IntToRoman {
    //贪心
    public String intToRoman(int num) {
        StringBuffer stringBuffer=new StringBuffer();
        int[] numb={1,4,5,9,10,40,50,90,100,400,500,900,1000};
        int i;
        String[] rom={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
        for(i=(rom.length-1);i>=0;i--){
            if(num>=numb[i]){
                num-=numb[i];
                stringBuffer.append(rom[i]);
                i++;
            }
        }
        return stringBuffer.toString();
    }

    public static void main(String[] args) {
        System.out.println(new IntToRoman().intToRoman(1994));
    }
}
